<template>
    <!--swiper的bug,如果数据是从网络获取的, 那么自动轮播到最后一页之后就不轮播了-->
  <!--只需要在swiper组件上面加上v-if="数据.length > 0"-->
  <swiper :options="swiperOption" class="banner" v-if="banners.length > 0">
    <!-- slides -->
    <swiper-slide v-for="value in banners" :key="value.bannerId" class="item">
      <a :href="value.url">
        <img v-lazy="value.pic" alt="">
      </a>
    </swiper-slide>
    <!-- Optional controls -->
    <div class="swiper-pagination"  slot="pagination"></div>
  </swiper>
</template>

<script>
import { swiper, swiperSlide} from 'vue-awesome-swiper'
import 'swiper/dist/css/swiper.css'
export default {
  name:"Banner",
  data() {
      return {
        swiperOption: {
          //loop: true, // 循环模式选项
          autoplay: {
            delay: 1000, // 自动切换的时间间隔，单位ms
            stopOnLastSlide: false, // 当切换到最后一个slide时停止自动切换
            disableOnInteraction: false // 用户操作swiper之后，是否禁止autoplay。
          },
          // 如果需要分页器
          pagination: {
            el: '.swiper-pagination'
          },
          observer: true,
          observeParents: true,
          observeSlideChildren: true
        }
      }
  },
  props:{
    banners:{
      type:Array,
      default: () => [],
      required:true
    }
  },
  components: {
    swiper,
    swiperSlide
  },
  
}
</script>

<style scoped lang="scss">
.banner{
  .item{
    img{
      width: 100%;
      height: 300px;
    }
  }
}
</style>

<style lang="scss">
  @import'../../assets/css/mixin';
  /*注意点: 如果想覆盖swiper的样式, 那么style标签不能是scoped的, 否则无法覆盖*/
.banner{
  .swiper-pagination-bullet{ //修改小圆点大小
    width:16px;
    height: 16px;
    opacity: 1;
    background: #fff;
  }
  .swiper-pagination-bullet-active{//修改小圆点激活颜色
    @include bg_color()
  }
}

</style>